#pragma once
#ifndef STOCK_API
#define STOCK_API __declspec(dllimport)
#endif

#include <atlbase.h>
#include <string>

// must after 5:0:0 PM
class CStkDataDownload
{
public:
	static CStkDataDownload& GetDownloader();	
	
	// http://ichart.finance.yahoo.com/table.csv?s=601666.SS&a=10&b=23&c=2006&d=03&e=23&f=2012&g=w
	bool DownloadYahooHistory(const std::wstring &code, const std::wstring &saveas);	
	bool DownloadYahooBetween(const std::wstring &code, const std::wstring &saveas, int start, int end);
	bool DownloadYahooFrom(const std::wstring &code, const std::wstring &saveas, int start);
	bool DownloadHistIndex(const std::wstring &code, const std::wstring &saveas, UINT startdate);
	bool DownloadSinaData(const std::wstring &code, bool bDecoCode, const std::wstring &saveas);	

private:
	CStkDataDownload(){};
	CStkDataDownload(const CStkDataDownload&);
	bool _DownloadToFile(const std::wstring &url, const std::wstring &file);
	//bool _ss2sh(std::wstring &code);
	//bool _sh2ss(std::wstring &code);
	const std::wstring _DecorateStkCodeForYahoo(const std::wstring &code);
	const std::wstring _DecorateStkCodeForSina(const std::wstring &code);
};

